//
//  WebViewController.m
//  方块布局
//
//  Created by KL on 16/11/23.
//  Copyright © 2016年 KM. All rights reserved.
//

#import "WebViewController.h"

@interface WebViewController ()<UISearchBarDelegate,UIWebViewDelegate>
@property (weak, nonatomic) IBOutlet UIWebView *web;

@end

@implementation WebViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UISearchBar *sea = [[UISearchBar alloc]init];
    self.navigationItem.titleView = sea;
    sea.delegate = self;
    sea.returnKeyType = UIReturnKeySearch;
    sea.keyboardType = UIKeyboardTypeURL;
    
    NSURL *url = [NSURL URLWithString:@"https://www.baidu.com"];
    NSURLRequest *re = [NSURLRequest requestWithURL:url];
    [self.web loadRequest:re];
    self.web.delegate = self;
    
}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    
}

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
    [searchBar resignFirstResponder];
    NSLog(@"%@",searchBar.text);
    NSString *str = searchBar.text;
    if (![str hasPrefix:@"http:"]) {
        str = [@"http://" stringByAppendingString:str];
    }
    NSURL *u = [NSURL URLWithString:str];
    NSURLRequest *r = [NSURLRequest requestWithURL:u];
    [self.web loadRequest:r];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
